using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace CocaCola_Inventory_System.Forms
{
    public partial class _ListFilter : UserControl
    {
        private DataTable Source;
        private string sort ="";
        private DataTable Destination;
        private string DisplayMember = "";
        public _ListFilter()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (SourceList.SelectedIndex < 0)
                return;
            DataRowView row = (DataRowView)SourceList.SelectedItem;
            Destination.Rows.Add(row.Row.ItemArray);
            row.Row.Delete();
            Destination.DefaultView.Sort = sort+" asc";
            Source.DefaultView.Sort = sort + " asc";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            foreach (DataRow row in Source.Rows)
            {
                Destination.Rows.Add(row.ItemArray);

            }
            Source.Clear();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (DestinationList.SelectedIndex < 0)
                return;
            DataRowView row = (DataRowView)DestinationList.SelectedItem;

            Source.Rows.Add(row.Row.ItemArray);
            row.Row.Delete();
            Destination.DefaultView.Sort = sort + " asc";
            Source.DefaultView.Sort = sort + " asc";
        }

        private void button5_Click(object sender, EventArgs e)
        {

            foreach (DataRow row in Destination.Rows)
            {
                Source.Rows.Add(row.ItemArray);

            }
            Destination.Clear();
        }

        public DataTable SourceDataTable
        {
            set
            {

                if (value != null&&value.Columns.Count>0)
                {
                    Source = value;
                    groupBox2.Enabled = true;
                    Destination = Source.Copy();
                    Destination.Clear();
                    if (sort == "")
                        sort = Destination.Columns[0].ColumnName;
                    if (DisplayMember == "")
                        DisplayMember = Source.Columns[0].ColumnName;
                    SourceList.DataSource = Source;
                    DestinationList.DataSource = Destination;
                    SourceList.DisplayMember = DisplayMember;
                    DestinationList.DisplayMember = DisplayMember;
                }
                
            }

            get
            {
                return Source;
            }
        }
        public DataTable DestinationTable
        {
            get
            {
                return Destination;
            }
        }

        public string SortColumnName
        {
            set
            {
                sort = value;
            }
        }

        private void _ListFilter_Load(object sender, EventArgs e)
        {

        }

        public string SourceLabel
        {
            set
            {
                SourceLbl.Text = value;
            }
        }

        public string DestinationLabel
        {
            set
            {
                DestinationLbl.Text = value;
            }
        }

        private void DestinationList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void SourceList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        public string ColumnNameDisplay
        {
            set
            {
                DisplayMember = value;
                SourceList.DisplayMember = DisplayMember;
                DestinationList.DisplayMember = DisplayMember;
            }
        }
    }
}
